package com.example.javalib.java;

import static java.lang.Float.NaN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * @Description:
 * @author: zcs
 * @email: 1059737741@qq.com
 * create at 2022/2/14 10:11
 */
public class StringTest {
    public static void main(String[] args) {
        String s1 = "a";
        String s2 = "b";

        String s6 = s1 + s2;
        String s66 = s1 + s2;

        System.out.println(s6 == s66); //false 两个都是使用了StringBulider来相加了
        String s7 = "a" + "b";
        String s77 = "ab";
        System.out.println(s7 == s77);//true
    }

    public static void main1(String[] args) {
        String str1 = new StringBuilder("计算机").append("软件").toString();
        System.out.println(str1.intern() == str1);//true

        String str2 = new StringBuilder("ja").append("va").toString();
        System.out.println(str2.intern() == str2);//true
    }

    public static void main2(String[] args) {
        int i = Integer.MAX_VALUE;
        System.out.println(i + 1);
        System.out.println(i + 1 < i);

    }

    public static void main3(String[] args) throws CloneNotSupportedException {
        System.out.println(Math.sqrt(-1));//NaN
        System.out.println(NaN == NaN);//false

//        Person person = new Person();
//        Object clone = person.clone();

        List<String> lists = new ArrayList<>();
        lists.add("aa");
        lists.add("bb");
        lists.add("cc");
        lists.add("dd");

        //错误方式
//        for (String string : strings) {
//            if(string == "bb"){
//                strings.remove(string);
//            }
//        }

        // 方式1
//        Iterator<String> it = lists.iterator();
//        while(it.hasNext()){
//            String temp = it.next();
//            if(temp == "bb"){
//                it.remove();
//            }
//        }

        // 方式2
        for (Iterator it = lists.iterator(); it.hasNext(); ) {
            String temp = (String) it.next();
            if (temp == "bb") {
                it.remove();
            }
        }

        System.out.println(lists);

    }



    public static void main4(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("aa", "value11");
        map.put("bb", "value22");
        map.put("cc", "value33");
        map.put("dd", "value44");

        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry.getKey() + "," + entry.getValue());
        }

//        map.keySet();
//        map.values();
//        map.entrySet();
        map.forEach(new BiConsumer<String, String>() {
            @Override
            public void accept(String key, String value) {
                System.out.println(key + "," + value);
            }
        });

    }


}
